package com.ptu.controller.user;

import com.ptu.server.FavoriteServer;
import com.ptu.util.Result;
import com.ptu.vo.ProductVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/favorite")
@Tag(name = "收藏模块 ")
public class FavoriteController {

    @Autowired
    FavoriteServer favoriteServer;

    // 收藏商品
    @Operation(summary = "收藏商品")
    @PostMapping("/add")
    public Result add(Integer ProductId) {
        System.out.println("收藏商品" + ProductId);
        favoriteServer.add(ProductId);
        return Result.success();
    }

    //取消收藏
    @Operation(summary = "取消收藏")
    @DeleteMapping("/delete")
    public Result delete(Integer ProductId) {
        System.out.println("取消收藏" + ProductId);
        favoriteServer.delete(ProductId);
        return Result.success();
    }

    @Operation(summary = "收藏列表")
    @GetMapping("/list")
    public List<ProductVO> list() {
        System.out.println("收藏列表");
        //返回收藏列表
        List<ProductVO> list = favoriteServer.getFavoriteList();
        System.out.println(list);
        return list;
    }

    @Operation(summary = "判断该商品是否收藏")
    @GetMapping("/isFavorite")
    public boolean isFavorite(Integer ProductId) {
        System.out.println("判断该商品是否收藏" + ProductId);
        //返回收藏列表
        boolean isFavorite = favoriteServer.isFavorite(ProductId);
        System.out.println(isFavorite);
        return isFavorite;
    }



}
